// pages/work-order/executeRecord/index.ts
const app = getApp()
Page({
  data: {
    statusList: [
      { id: 1, name: '已出发' },
      { id: 2, name: '开始处理' },
      { id: 3, name: '维修报价' },
      { id: 4, name: '已完结' },
    ],
    currentStatus: 0,
    problemVisible: false,
    panalType: 0,
    expandInfo: false,
    panalData: {
      statusText: '处理中',
      dateTime: '2025-03-29 09:23',
      executor: '陈师',
      tip: '等待维修人员确认',
    },
    avatarImg: app.getImgUrl('avatar2.webp'),
    excuteData: {
      excutor: '张弘韬',
      excutorScore: 4.8,
      excutorCompany: '联创物联科技有限公司',
    },
    problem: {
      icons: ['icon-yinliang1', 'icon-play-filled', 'icon-image-fill', 'icon-qubiezhen'],
      list: [
        { id: 0, label: '地址', value: '西昌西路11号大厦35号', icon: 'icon-feiji' },
        { id: 1, label: '项目', value: '幼儿园项目', icon: '' },
        { id: 2, label: '所属客户', value: '黄xx', icon: 'icon-phone' },
        { id: 3, label: '故障', value: '设备检测到交换机与xx通讯问题', icon: '' },
        { id: 4, label: '计划时限', value: '2025-02-06  13：48前', icon: '' },
      ]
    },
    delayDate: '',
    delayDateStr: '',
    delayTime: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.setData({
      delayDate:new Date().getTime()
    })
  },
  start() {
    this.setData({
      currentStatus: 1
    })
  },
  navigateTo(e) {
    app.navigateTo(e.currentTarget.dataset.url, e.currentTarget.dataset.type)
  },
  showPanal(e) {
    if (e.currentTarget.dataset.type) {
      this.setData({
        panalType: e.currentTarget.dataset.type,
        currentStatus: 2
      })
    }
    const alert = this.selectComponent('#v-alert')
    alert.showAlert()
  },
  hidePanal() {
    const alert = this.selectComponent('#v-alert')
    alert.hideAlert()
  },
  changePanal(e) {
    if (e.currentTarget.dataset.type) {
      this.setData({
        panalType: e.currentTarget.dataset.type,
        currentStatus: 2
      })
    }
  },
  toggleProblem() {
    this.setData({
      problemVisible: this.data.problemVisible ? false : true
    })
  },
  handleClosePanal() {
    this.setData({
      panalType: 0,
      expandInfo: false,
    })
  },
  showInfoMore() {
    this.setData({
      expandInfo: this.data.expandInfo ? false : true
    })
  },
  handleConfirm(e) {
    this.hidePanal()
    wx.showToast({
      title: '操作成功',
      icon: 'success',
      duration: 1500
    })
  },
  showDatePicker() {
    const ctx = this.selectComponent('#date-drawer')
    ctx.toggleDrawer()
  },
  showTimePicker() {
    const ctx = this.selectComponent('#time-drawer')
    ctx.toggleDrawer()
  },
  onDateInput(e) {
    this.setData({
      delayDate: e.detail,
      delayDateStr: app.dateFormatter(e.detail)
    })
    const ctx = this.selectComponent('#date-drawer')
    ctx.toggleDrawer()
  },
  onTimeInput(e) {
    this.setData({
      delayTime: e.detail
    })
    const ctx = this.selectComponent('#time-drawer')
    ctx.toggleDrawer()
  },
})